package com.xt.purchasingsystem.service.impl.productDesignServiceImpl.proFileManageServiceImpl.proFileDelManageServiceImpl;

import com.xt.purchasingsystem.dto.DFileDto;
import com.xt.purchasingsystem.mapper.DFileMapper;
import com.xt.purchasingsystem.model.DFile;
import com.xt.purchasingsystem.service.productDesignService.proFileManageService.proFileDelManageService.ProductFileDelManageService;
import com.xt.purchasingsystem.utils.PageBean;
import com.xt.purchasingsystem.utils.Result;
import com.xt.purchasingsystem.utils.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 产品档案删除管理业务实现类
 */
@Service
@Transactional

public class ProductFileDelManageServiceImpl implements ProductFileDelManageService {
    @Autowired
    private DFileMapper dFileMapper;


    @Override
    public Result queryDfileByHaveDelAndDto(DFileDto dfileDto) {
        int rowCount = dFileMapper.queryRowCountByHaveDelAndDto(dfileDto);
        PageBean pageBean = new PageBean(dfileDto.getPageSize(), dfileDto.getCurrNo(), rowCount);
        dfileDto.setCurrNo(pageBean.getStart());
        dfileDto.setPageSize(pageBean.getEnd());
        List<DFile> dFiles = dFileMapper.queryDfileByHaveDelAndDto(dfileDto);
        pageBean.setPageList(dFiles);
        return ResultFactory.buildSuccessResult("查询成功", pageBean);
    }

    @Override
    public Result queryDfileByDelRecoveryAndDto(DFileDto dfileDto) {
        int rowCount = dFileMapper.queryRowCountByDelRecoveryAndDto(dfileDto);
        PageBean pageBean = new PageBean(dfileDto.getPageSize(), dfileDto.getCurrNo(), rowCount);
        dfileDto.setCurrNo(pageBean.getStart());
        dfileDto.setPageSize(pageBean.getEnd());
        List<DFile> dFiles = dFileMapper.queryDfileByDelRecoveryAndDto(dfileDto);
        pageBean.setPageList(dFiles);
        return ResultFactory.buildSuccessResult("查询成功", pageBean);
    }

    @Override
    public Result queryDfileByPermanentDeleteAndDto(DFileDto dfileDto) {
//
//        int rowCount = dFileMapper.queryRowCountByPermanentDeleteAndDto(dfileDto);
//        PageBean pageBean = new PageBean(dfileDto.getPageSize(), dfileDto.getCurrNo(), rowCount);
//        dfileDto.setCurrNo(pageBean.getStart());
//        dfileDto.setPageSize(pageBean.getEnd());
//        List<DFile> dFiles = dFileMapper.queryDfileByPermanentDeleteAndDto(dfileDto);
//        pageBean.setPageList(dFiles);
//        return ResultFactory.buildSuccessResult("查询成功", pageBean);
        return null;
    }

    @Override
    public Result deleteDFileById(Integer id) {
        int i = dFileMapper.deleteDFileById(id);
        if (i == 1) {
            return ResultFactory.buildSuccessResult("删除成功");
        } else {
            return ResultFactory.buildFailResult("删除失败");
        }
    }

    @Override
    public Result recoverDFileById(Integer id) {
        int i = dFileMapper.recoverDFileById(id);
        if (i == 1) {
            return ResultFactory.buildSuccessResult("恢复成功");
        } else {
            return ResultFactory.buildFailResult("恢复失败");
        }
    }

    @Override
    public Result permanentDelDFile(Integer id) {
        int i = dFileMapper.deleteByPrimaryKey(id);
        if (i == 1) {
            return ResultFactory.buildSuccessResult("永久删除成功");
        } else {
            return ResultFactory.buildFailResult("永久删除失败");
        }
    }





}
